﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class userbackstage_delete : System.Web.UI.Page
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString.ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        string release = Session["name"].ToString();
        string sqlstr = "select * from info where release='" + release + "'";
        SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        if (!IsPostBack)
        {
            BindData();
        }
    }
    public void BindData()
    {

        string release = Session["name"].ToString();
        string sqlstr = "select * from info where release='" + release + "'";

        SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindData();
    }
    

    public bool ExceSQL(string strSqlCom)
    {


        SqlCommand sqlcom = new SqlCommand(strSqlCom, conn);
        try
        {
            if (conn.State == System.Data.ConnectionState.Closed)
            { conn.Open(); }
            sqlcom.ExecuteNonQuery();
            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            conn.Close();
        }
    }

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindData();
    }


    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string delete_sql = "delete from info where id= '" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
        bool delete = ExceSQL(delete_sql);
        if (delete)
        {
            Response.Write("<script language=javascript> alert('删除成功！')</script>");
            BindData();
        }
        else
        {
            Response.Write("<script language =javascript> alert(删除失败！)</script>");
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[6].Text == "False")
            {
                e.Row.Cells[6].Text = "<span style='color:red'>" + "未审核" + "</span>";
            }
            else
            {
                e.Row.Cells[6].Text = "<span style='color:blue'>" + "已审核" + "</span>";
            }
        }
    }
}